<script type="text/javascript">
    function typeListTreeNodeClick(event, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj(treeId);
        var form = $.CurrentNavtab.find("#typeForm");

        form.find("input[name='name']").val(treeNode["name"]);
        form.find("input[name='sort']").val(treeNode["sort"]);
        form.find("input[name='typeId']").val(treeNode["id"]);

        var opt = form.find("select[name='pid'] > option");
        $.each(opt, function () {
            $(this)[0].selected = false;
            $(this).removeAttr("selected");
            
            if ($(this).val() == treeNode["pid"]) {
                $(this)[0].selected = true;
                $(this).attr("selected", "selected");
            }
        });

        event.preventDefault();
    }

    $.CurrentNavtab.find("#addTypeBtn").on("click", function () {
        var form =  $.CurrentNavtab.find("#typeForm");
        form.attr("action", "{:U('Admin/Type/addType')}");
        form.bjuiajax("ajaxForm", {
            callback: function (data) {
                $(this).bjuiajax('ajaxDone', data).navtab('refresh');
                $(this).navtab("refresh", "Admin/Attr/addAttr");
            }
        });
    });
    
    $.CurrentNavtab.find("#updTypeBtn").on("click", function () {
        var form =  $.CurrentNavtab.find("#typeForm");
        form.attr("action", "{:U('Admin/Type/updType')}");
        form.bjuiajax("ajaxForm", {
            callback: function (data) {
                $(this).bjuiajax('ajaxDone', data).navtab('refresh');
                $(this).navtab("refresh", "Admin/Attr/addAttr");
            }
        });
    });
    
    $.CurrentNavtab.find("#delTypeBtn").on("click", function () {
        var form =  $.CurrentNavtab.find("#typeForm");
        form.attr("action", "{:U('Admin/Type/delType')}");
        form.bjuiajax("ajaxForm", {
            callback: function (data) {
                $(this).bjuiajax('ajaxDone', data).navtab('refresh');
                $(this).navtab("refresh", "Admin/Attr/addAttr");
            }
        });
    });
</script>
<div class="bjui-pageContent">
    <div class="col-md-4 col-sm-12">
        <div style="overflow:auto;">
            <ul id="typeListTree" class="ztree" data-toggle="ztree" data-options="{expandAll:true,onClick:typeListTreeNodeClick}">
                <notempty name="allTypeData">
                    <foreach name="allTypeData" item="vo" key="k">
                        <li data-id="{$vo.id}" data-pid="{$vo.pid}" data-sort="{$vo.sort}">{$vo.name}</li>
                    </foreach>
                </notempty>
            </ul>
        </div>
    </div>
    <div class="col-md-8 col-sm-12">
        <div id="typeInfo">
            <form id="typeForm">
                <div class="form-group">
                    <label for="name" class="control-label x85">种类名称：</label>
                    <input type="text" name="name" id="name" value="" data-rule="required" size="20">
                </div>
                <div class="form-group">
                    <label for="pid" class="control-label x85">父级种类：</label>
                    <select name="pid" id="pid" class="form-control" style="width:200px;">
                        <option value="0">请选择</option>
                        <notempty name="allTypeData">
                            <foreach name="allTypeData" item="vo" key="k">
                                <option value="{$vo.id}">{$vo.space}{$vo.name}</option>
                            </foreach>
                        </notempty>
                    </select>
                    <span>(*如果不选,默认顶级)</span>
                </div>
                <div class="form-group">
                    <label for="sort" class="control-label x85">排序：</label>
                    <input type="text" name="sort" id="sort" value="0" size="20">
                    <span>(*值越小越前)</span>
                </div>
                <div class="form-group">
                    <label class="control-label x85"></label>
                    <if condition="checkRule('Admin/Type/addType')">
                    <input type="button" class="btn btn-green" id="addTypeBtn" value="添加种类">
                    </if>
                    <if condition="checkRule('Admin/Type/updType')">
                    <input type="button" class="btn btn-green" id="updTypeBtn" value="更新种类">
                    </if>
                    <if condition="checkRule('Admin/Type/delType')">
                    <input type="button" class="btn btn-red" id="delTypeBtn" value="删除种类">
                    </if>
                    <input type="hidden" name="typeId" value="">
                </div>
            </form>
        </div>
    </div>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="close">关闭</button></li>
    </ul>
</div>